package com.settlement.system.model.entity.common;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.settlement.system.common.enums.CostAllocationEnum;
import com.settlement.system.converter.*;
import io.swagger.annotations.ApiModelProperty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

import org.hibernate.validator.constraints.NotEmpty;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
/**
 * RR-费用分摊表
 * @author xiaochuan
 * @since 2023-01-06
 */
@Data
@ExcelIgnoreUnannotated
@HeadStyle(fillBackgroundColor = 9,fillForegroundColor = 9)
@HeadRowHeight(value = 20)
@HeadFontStyle(fontHeightInPoints = 14)
public class TblCostAllocationDetail extends BaseModel implements Serializable {


    /**
     * 统一汇总ID
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "统一汇总ID")
    @ApiModelProperty(value = "统一汇总ID")
    private String summaryId;

    /**
     * 权数类型。1，当月发退货；2，近3月发货；
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "权数类型",converter = WeightTypeConvert.class)
    @ApiModelProperty(value = "权数类型。1，当月发退货；2，近3月发货；")
    @NotBlank(message = "权数类型不能为空")
    @Pattern(regexp="^[1-2]{1}$",message="[权数类型]只能为\"当月发退货\"或\"近三月发货\"")
    private String weightType;

    /**
     * 会计期间
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "会计期间",converter = DateFormatYearMonthPeriodConvert.class)
    @ApiModelProperty(value = "会计期间")
    @NotNull(message="会计期间不能为空")
    @JsonFormat(pattern = "yyyyMM月", timezone = "GMT+8")
    private Date accountingPeriod;

    /**
     * 入账主体
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "入账主体")
    @ApiModelProperty(value = "入账主体")
    @NotEmpty(message="入账主体不能为空")
    private String companyNo;

    /**
     * 渠道编码
     */
    @ApiModelProperty(value = "渠道编码")
    private String channelNo;

    /**
     * 渠道
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "渠道")
    @ApiModelProperty(value = "渠道")
    @NotBlank(message = "渠道不能为空")
    private String channelName;


    /**
     * 店铺编码
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "店铺编码")
    @ApiModelProperty(value = "店铺编码")
    @NotBlank(message = "店铺编码不能为空")
    private String shopNo;

    /**
     * 店铺名称
     */
    @ColumnWidth(30)
    @ExcelProperty(value = "店铺名称")
    @ApiModelProperty(value = "店铺名称")
    private String shopName;

    /**
     * 记账项目
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "记账项目")
    @ApiModelProperty(value = "记账项目")
    @NotBlank(message = "记账项目不能为空")
    private String recordAccountProject;

    /**
     * 凭证类型
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "凭证类型")
    @ApiModelProperty(value = "凭证类型")
    @NotBlank(message = "凭证类型不能为空")
    private String voucherType;

    /**
     * 票前票后，票前1、票后2、不涉及3
     */
    @ApiModelProperty(value = "票前票后，票前1、票后2、不涉及3")
    @ExcelProperty(value = "票前票后",converter = BeforeOrAfterTicketConvert.class)
    @NotEmpty(message = "票前票后不能为空")
    @Pattern(regexp="^[1-3]{1}$",message="【票前票后】的值只能是[票前]或[票后]或[不涉及]")
    private String beforeOrAfterTicket;

    @ColumnWidth(13)
    private String beforeOrAfterTicketStr;

    /**
     * 品牌部简称
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "品牌部简称")
    @ApiModelProperty(value = "品牌部简称")
    private String brandUnitNameShort;

    /**
     * 品牌部编码
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "品牌部编码")
    @ApiModelProperty(value = "品牌部编码")
    @NotBlank(message = "品牌部编码不能为空")
    private String brandUnitNo;

    /**
     * 品牌编码
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "品牌编码")
    @ApiModelProperty(value = "品牌编码")
    private String brandNo;

    /**
     * 品牌名称
     */
    private String brandName;

    /**
     * NC品牌
     */

    @ApiModelProperty(value = "NC品牌")
    private String ncBrandName;

    /**
     * NC品牌编码
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "NC品牌")
    @NotBlank(message = "NC品牌不能为空")
    @ApiModelProperty(value = "NC品牌编码")
    private String ncBrandNo;

    /**
     * 分摊金额
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "分摊金额")
    @ApiModelProperty(value = "分摊金额")
    @NotNull(message = "分摊金额不能为空")
    private BigDecimal shareAmount;

    public void setShareAmount(BigDecimal shareAmount) {
        this.shareAmount = shareAmount;
        if(shareAmount!=null){
            this.shareAmount = shareAmount.setScale(2, RoundingMode.HALF_UP);
        }
    }

    /**
     * 不含税金额
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "不含税金额")
    @ApiModelProperty(value = "不含税金额")
    @NotNull(message = "不含税金额不能为空")
    private BigDecimal noTaxAmount;

    /**
     * 税额
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "税额")
    @ApiModelProperty(value = "税额")
    @NotNull(message = "税额不能为空")
    private BigDecimal taxAmount;


    public void setNoTaxAmount(BigDecimal noTaxAmount) {
        this.noTaxAmount = noTaxAmount;
        if(noTaxAmount!=null){
            this.noTaxAmount = noTaxAmount.setScale(2, RoundingMode.HALF_UP);
        }
    }

    public void setTaxAmount(BigDecimal taxAmount) {
        this.taxAmount = taxAmount;
        if(taxAmount!=null){
            this.taxAmount = taxAmount.setScale(2, RoundingMode.HALF_UP);
        }
    }

    /**
     * 记账状态(0、未生成凭证，1、生成凭证中，2、已生成凭证，3、撤销生成中，4、推送NC中，5、已推送NC，6、推送NC失败，7、无需生成凭证)
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "记账状态",converter = AccountStatusConvert.class)
    @ApiModelProperty(value = "记账状态(0、未生成凭证，1、生成凭证中，2、已生成凭证，3、撤销生成中，4、推送NC中，5、已推送NC，6、推送NC失败，7、无需生成凭证)")
    private String accountStatus;

    /**
     * 记账失败原因
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "记账失败原因")
    @ApiModelProperty(value = "记账失败原因")
    private String accountFailDesc;

    /**
     * 推送FAS状态(0无需推送，1未推送，2推送中，3推送完成，4推送失败)
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "推送FAS状态",converter = PushFasStatusConvert.class)
    @ApiModelProperty(value = "推送FAS状态(0无需推送，1未推送，2推送中，3推送完成，4推送失败)")
    private String pushFasStatus;

    /**
     * 推送失败原因
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "推送失败原因")
    @ApiModelProperty(value = "推送失败原因")
    private String fasReturnMsg;



    /**
     * 创建人
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "创建人")
    @ApiModelProperty(value = "创建人")
    public String createUser;

    /**
     * 唯一ID
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "唯一ID")
    @ApiModelProperty(value = "唯一ID")
    public String id;

    /**
     * NC凭证号
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "NC凭证号")
    @ApiModelProperty(value = "NC凭证号")
    private String ncVoucherNo;


    public void setBeforeOrAfterTicket(String beforeOrAfterTicket) {
        this.beforeOrAfterTicket = beforeOrAfterTicket;
        if(StringUtils.isNotEmpty(beforeOrAfterTicket)){
            this.beforeOrAfterTicketStr = beforeOrAfterTicket
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.AFTER.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.AFTER.getName())
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.BEFORE.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.BEFORE.getName())
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.NOT_INVOLVE.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.NOT_INVOLVE.getName());
        }
    }

    private String weightId;

    private String refId;

    private String pushFasId;

    /**
     * 数据来源
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "数据来源",converter = SourceTypeConvert.class)
    @ApiModelProperty(value = "数据来源(0系统生成，1导入调整，2手工导入)")
    private String sourceType;

    /**
     * 账单类型
     */
    @ExcelProperty(value = "账单类型")
    @ApiModelProperty(value = "账单类型")
    @NotBlank(message = "账单类型不能为空")
    private String billType;



    /**
     * NC供应商档案
     */
    @ExcelProperty(value = "NC供应商档案")
    @ApiModelProperty(value = "NC供应商档案")
    @NotBlank(message = "NC供应商档案不能为空")
    private String ncSupplierRecord;

    /**
     * 是否原数据相反数
     */
    @ExcelProperty(value = "是否原数据相反数")
    @ApiModelProperty(value = "是否原数据相反数(是/否)")
    @NotBlank(message = "是否原数据相反数不能为空")
    private String ifOriginData;
}
